<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改问题')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-question-edit" th:object="${wbQuestion}">
            <input name="questionId" th:field="*{questionId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">问题内容：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{questuionContent}">
                    <div class="summernote" id="questuionContent"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">知识点类型：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="questionTypeId">
                        <option th:value="0">请选择</option>
                        <option th:each="type : ${wbQuestionTypeList}" th:value="${type.typeId}" th:text="${type.typeName}"
                                th:selected="${type.typeId}==*{questionTypeId}">
                            JavaEE
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">题型：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="itemTypeId">
                        <option th:value="0">请选择</option>
                        <option th:each="item : ${wbItemTypeList}" th:value="${item.itemTypeId}" th:text="${item.itemTypeName}"
                                th:selected="${item.itemTypeId}==*{itemTypeId}">
                            单选题
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">选项内容：</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">A：</label>
                <div class="col-sm-9">
                    <input name="options[0].optionId" th:field="*{options[0].optionId}" type="hidden">
                    <input type="text" name="options[0].optionContent" th:value="*{options[0].optionContent}" class="form-control" placeholder="请输入选项内容">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">B：</label>
                <div class="col-sm-9">
                    <input name="options[1].optionId" th:field="*{options[1].optionId}" type="hidden">
                    <input type="text" name="options[1].optionContent" th:value="*{options[1].optionContent}" class="form-control" placeholder="请输入选项内容">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">C：</label>
                <div class="col-sm-9">
                    <input name="options[2].optionId" th:field="*{options[2].optionId}" type="hidden">
                    <input type="text" name="options[2].optionContent" th:value="*{options[2].optionContent}" class="form-control" placeholder="请输入选项内容">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">D：</label>
                <div class="col-sm-9">
                    <input name="options[3].optionId" th:field="*{options[3].optionId}" type="hidden">
                    <input type="text" name="options[3].optionContent" th:value="*{options[3].optionContent}" class="form-control" placeholder="请输入选项内容">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">答案选项：</label>
                <div class="col-sm-9">
                    <label class="check-box">
                        <input type="checkbox" value="true" name="optionRW[0]" th:attr="checked=*{options[0].isRight}?true:false">A</label>
                    <label class="check-box">
                        <input type="checkbox" value="true" name="optionRW[1]" th:attr="checked=*{options[1].isRight}?true:false">B</label>
                    <label class="check-box">
                        <input type="checkbox" value="true" name="optionRW[2]" th:attr="checked=*{options[2].isRight}?true:false">C</label>
                    <label class="check-box">
                        <input type="checkbox" value="true" name="optionRW[3]" th:attr="checked=*{options[3].isRight}?true:false">D</label>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">最高分：</label>
                <div class="col-sm-8">
                    <input name="topScore" th:field="*{topScore}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">最低分：</label>
                <div class="col-sm-8">
                    <input name="lowestMark" th:field="*{lowestMark}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "wbgame/question";
        $("#form-question-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-question-edit').serialize());
            }
        }

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
</body>
</html>